package com.example.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.bean.Girl;
import com.example.dao.GirlRespository;
import com.example.enums.CodeEnum;
import com.example.exception.CommonException;

@Service
public class GirlService {

	@Autowired
	private GirlRespository girlRespository;
	
	@Transactional
	public void createTwoGirl() {
		Girl g1 = new Girl();
		g1.setCupSize("11");
		g1.setAge(19);
		Girl g2 = new Girl();
		g2.setCupSize("11");
		g2.setAge(29);
		girlRespository.save(g1);
		girlRespository.save(g2);
	}
	
	public Girl getAge(Integer id) throws Exception{
		Girl girl = girlRespository.getOne(id);
		System.out.println(girl.toString());
		if(girl.getAge()<16) {
			throw new CommonException(CodeEnum.ERRO_US);
		}
		return girl;
	}
}
